package com.clzw.module_activity.fragment

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.clzw.module_activity.BR
import com.clzw.module_activity.R
import com.clzw.module_activity.adapter.EnlistsAdapter
import com.clzw.module_activity.databinding.FragmentBullentinListBinding
import com.clzw.module_activity.databinding.FragmentEnlistsListBinding
import com.clzw.module_activity.viewmodel.EnlistsViewModel
import com.czl.base.base.BaseFragment
import com.czl.base.config.AppConstants
import com.czlw.module_activity.adapter.BulletinAdapter
import com.czlw.module_activity.viewmodel.BulletinListViewModel

@Route(path = AppConstants.Router.Activities.F_ACTIVITIES_ENLIST_LIST)
class EnlistsListFragment: BaseFragment<FragmentEnlistsListBinding, EnlistsViewModel>() {

    private lateinit var mAdapter: EnlistsAdapter
    override fun initContentView(): Int {
        return R.layout.fragment_enlists_list
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }
    override fun initData() {
        viewModel.tvTitle.set("报名详情")
        viewModel.toolbarRightTextColor.set("#00A468")
        initAdapter()
        reload()
    }

    private fun initAdapter() {
        viewModel.activityId=arguments?.getString(AppConstants.BundleKey.ACTIVITY_ID).toString()
        mAdapter = EnlistsAdapter(this)
        binding.ryCommon.apply {
            layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
            adapter = mAdapter
        }
    }
    override fun initViewObservable() {
        viewModel.uc.refreshListEvent.observe(this, {
            binding.smartCommon.autoRefresh()
        })
        viewModel.uc.loadCompleteEvent.observe(this, { data ->
            handleRecyclerviewData(
                data == null,
                data as MutableList<*>?,
                mAdapter,
                binding.ryCommon,
                binding.smartCommon,
                1,
                true
            )
        })
    }
    override fun reload() {
        super.reload()
        binding.smartCommon.autoRefresh()
    }
}